package model.remito;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToMany;
import dtos.RemitoDTO;

@MappedSuperclass
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Remito {
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int nro;
	
	private Date fechaEmision;

	@OneToMany (cascade=CascadeType.ALL)
    @JoinColumn(name="nroRemito")
	private Set<ItemRemito> items;
	
	public Remito()
	{
		items = new HashSet<ItemRemito>();
	}
	
	public Remito(int nro, Date fechaEmision)
	{
		this.nro = nro;
		this.fechaEmision = fechaEmision;
		this.items = new HashSet<ItemRemito>();
	}

	public int getNro() {
		return nro;
	}

	public void setNro(int nro) {
		this.nro = nro;
	}

	public Date getFechaEmision() {
		return fechaEmision;
	}

	public void setFechaEmision(Date fechaEmision) {
		this.fechaEmision = fechaEmision;
	}

	public Set<ItemRemito> getItems() {
		return items;
	}

	public void setItems(Set<ItemRemito> items) {
		this.items = items;
	}
	
	public void addItem(ItemRemito item) {
		this.items.add(item);
	}
	
	public abstract RemitoDTO getView();
}
